/* GUI CONVERTED from rcsochg.p (converter v1.76) Mon Jul 30 07:02:35 2001 */
/* rcsochg.p - SALES ORDER CHANGE ON CONTAINER, UPDATE CONTAINER&LINE CHARGES*/
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                       */
/* All rights reserved worldwide.  This is an unpublished work.              */
/* $Revision: 1.2 $                                                      */
/*                                                                           */
/*----------------------------------------------------------------------------
  Purpose: This program is called from the Pre-Shipper/ShipperWorkBench and
           Container Workbench when the sales order/line are changed
           on an abs_mstr for an item within a container. The change in sales
           order will cause a change in the abs_id and therefore the user
           field records (absd_det) and the line charge records (absl_det)
           need to be updated.  The user field records will be updated.
           The line charge records for the old sales order will be deleted.

  Notes:
----------------------------------------------------------------------------*/
/*                                                                           */
/* $Revision: 1.2 $       BY: Ellen Borden   DATE: 07/16/01 ECO: *P006*  */
/*V8:ConvertMode=Maintenance                                                 */
/*                                                                           */
/* -----  W A R N I N G  -----  W A R N I N G  -----  W A R N I N G  -----   */
/*                                                                           */
/*         THIS PROGRAM IS A BOLT-ON TO STANDARD PRODUCT MFG/PRO.            */
/* ANY CHANGES TO THIS PROGRAM MUST BE PLACED ON A SEPARATE ECO THAN         */
/* STANDARD PRODUCT CHANGES.  FAILURE TO DO THIS CAUSES THE BOLT-ON CODE TO  */
/* BE COMBINED WITH STANDARD PRODUCT AND RESULTS IN PATCH DELIVERY FAILURES. */
/*                                                                           */
/* -----  W A R N I N G  -----  W A R N I N G  -----  W A R N I N G  -----   */
/*                                                                           */

{mfdeclre.i}

define input parameter ipAbsRecid as recid no-undo.
define input parameter ipOldOrder like abs_order no-undo.
define input parameter ipOldLine  like abs_line  no-undo.
define input parameter ipOldAbsId like abs_id no-undo.
define input parameter ipSourcePgm as character  no-undo.

for first abs_mstr no-lock where
   recid(abs_mstr) = ipAbsRecid:
end.

if not available abs_mstr then leave.

if ipSourcePgm <> "rcshwbb.p" then
   ipOldAbsId = abs_id.

   /* DELETE THE LINE CHARGES FROM THE SHIPPER */
   /* DELETE THE LINE CHARGES CREATED ON THE SALES ORDER    */
   /* FROM THE SHIPPER AND DECREMENT THE TIMES CHARGED ON   */
   /* THE LINE CHARGES THAT ORIGINATED FROM THE SALES ORDER,*/
   /* WHICH WILL NOT BE DELETED                             */

for each absl_det exclusive-lock
   where
      absl_abs_id = ipOldAbsId
   and absl_abs_shipfrom = abs_shipfrom:

   for each sodlc_det exclusive-lock
      where
         sodlc_order = absl_order
      and sodlc_ord_line = absl_ord_line
      and sodlc_lc_line = absl_lc_line:

      if sodlc_owned_by = ipOldAbsId then
         delete sodlc_det.
      else
         if sodlc_times_charged > 0 then
           sodlc_times_charged = sodlc_times_charged - 1.
   end.
   delete absl_det.
end. /*FOR EACH ABSL_DET*/

/* UPDATE THE ABS_ID ON THE USER FIELDS FROM THE SHIPPER */


if ipSourcePgm = "rcshwbb.p" then do:
   for each absd_det exclusive-lock
      where
         absd_abs_id = ipOldAbsId
      and absd_shipfrom = abs_shipfrom:

      absd_abs_id = "i" + abs_par_id +
                    abs_shipfrom + abs_order + abs_line +
                    abs_item + abs_loc + abs_lotser + abs_ref.
   end.
end.
